package com.wzx.selfuse.interceptor;

import com.wzx.selfuse.entity.User;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//拦截器
public class SelfInterceptor extends HandlerInterceptorAdapter {
/*  private static final List<String> letPaths= Arrays.asList("/index.jsp","/user/getuser","/getuser",
            "/user","/address","/address/addressListStr","/addressListStr","/address","/address/address",
            "/user/userDetail","/user","userDetail");*/

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

      /*  if(letPaths.contains(request.getServletPath())){
            System.out.println(request.getServletPath());
            System.out.println("需要放行");
            return super.preHandle(request, response, handler);
        }*/

        String user = (String) request.getSession().getAttribute("user");
        if (user == null) {
            response.sendRedirect(request.getContextPath()+"/login.jsp");
            return  false;
        }
        return super.preHandle(request, response, handler);

    }
}
